package com.xbongbong.pro.statistic.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 *  钻取字段所属类别：chartClassify 分类、chartSeries 系列、rowGroupAttr 行分组、colGroupAttr 列分组
 * @author xbongbong
 * @version v1.0
 * @date 2022/9/7 16:34
 * @since v1.0
 */
@Getter
public enum DrillFieldEnum {
    /**
     * 分类
     */
    CHART_CLASSIFY("chartClassify", Arrays.asList(ChartTypeEnum.BAR_CHART.getCode(), ChartTypeEnum.LINE_CHART.getCode(), ChartTypeEnum.AREA_CHART.getCode(), ChartTypeEnum.PIE_CHART.getCode(), ChartTypeEnum.BROADWISE_BAR_CHART.getCode(), ChartTypeEnum.SCATTER_CHART.getCode())),
    /**
     * 系列
     * 饼图只有分类，无系列
     */
    CHART_SERIES("chartSeries", Arrays.asList(ChartTypeEnum.BAR_CHART.getCode(), ChartTypeEnum.LINE_CHART.getCode(), ChartTypeEnum.AREA_CHART.getCode(), ChartTypeEnum.BROADWISE_BAR_CHART.getCode(), ChartTypeEnum.SCATTER_CHART.getCode())),
    /**
     * 行分组字段
     */
    ROW_GROUP_ATTR("rowGroupAttr", Arrays.asList(ChartTypeEnum.DATA_STATISTICS_TABLE.getCode())),
    /**
     * 列分组字段
     */
    COL_GROUP_ATTR("colGroupAttr", Arrays.asList(ChartTypeEnum.DATA_STATISTICS_TABLE.getCode())),
    ;

    /**
     * 枚举值
     */
    private String alias;
    /**
     * 枚举值
     */
    private List<Integer> supportDrillChartTypeList;

    DrillFieldEnum(String alias, List<Integer> supportDrillChartTypeList) {
        this.alias = alias;
        this.supportDrillChartTypeList = supportDrillChartTypeList;
    }

    /**
     * 通过alias获取枚举
     * @param alias
     * @return com.xbongbong.pro.statistic.enums.DrillFieldEnum
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static DrillFieldEnum getByAlias(String alias) {
        for (DrillFieldEnum cache : values()) {
            if (Objects.equals(alias, cache.alias)) {
                return cache;
            }
        }
        return null;
    }

    /**
     * 通过图表类型或者行列、分类、系列字段信息 （图就是分类、系列。表就是行列分组。饼图没有列）
     *
     * @param chartType 图表类型
     * @return 符合条件的分类、系列、行列分组信息
     */
    public static List<DrillFieldEnum> getByChartType(Integer chartType) {
        List<DrillFieldEnum> list = new ArrayList<>();
        for (DrillFieldEnum cache : values()) {
            for (Integer type : cache.supportDrillChartTypeList) {
                if (Objects.equals(type, chartType)) {
                    list.add(cache);
                }
            }

        }
        return list;
    }

}
